1. Field of the Invention
The present invention relates to the field of computer software and, more particularly, to stateless session Enterprise Java Beans.
2. Description of the Related Art
Enterprise Java Beans (EJB) are reusable and portable software components that model business objects and processes. EJBs can run on any EJB enterprise server compliant with the Java 2 Enterprise Edition (J2EE) specification. The EJB server can manage many significant overhead issues such as object persistence, security, and transaction management. There are multiple types of EJBs including entity beans, session beans, and message driven beans.
A session EJB is a reusable component that maintains conversations or sessions with clients. Two types of session EJBs are stateful and stateless EJBs. A stateful session EJB maintains a conversational state with one client for the duration of a single session. This implies that the stateful session EJB can maintain instance variables across multiple invocations from the same client during a single session. Once the client finishes interacting with the stateful session EJB, the session for the EJB ends and all state data for the stateful EJB is discarded.
A stateless session bean does not maintain a conversational state for each individual client. When a client requests a stateless session bean, the client receives an existing instance from a pool of previously created stateless session beans. If no previously created EJBs exist in the pool, a new instance is created. A stateless session bean is removed from the pool for the duration of any method call from a client. After the method completes, the stateless session bean is returned to the pool. Each invocation of a stateless session EJB should be considered as a request to a brand new object instance, since any instance-variable state will be lost between invocations. The transient nature of-stateless session EJBs allows an EJB container to reuse EJB instances, which may optimize performance in many situations.
The creation of a stateless session EJB can require startup overhead such as allocating sufficient memory for the EJB and initializing reference variables for the EJB. The first client to request access to a stateless session EJB can experience a performance lag when no pre-existing EJB is available for use due to the overhead in creating a new EJB instance. This overhead can cause a delay in program execution. The resulting delay can be unacceptable in many situations, including situations where real-time and/or near real-time responses are necessary.
Conventional programming practices do not provide a technique for initializing a multitude of stateless session EJBs. The problem with initializing stateless session EJBs is that if there is an existing instance of the EJB that is “free,” subsequent creation attempts will use the free instance of the EJB instead of creating a new instance of the EJB and adding the new instance to the pool of “free” EJBs. That is, EJBs are created on the first real method invocation of an object and simply calling a create: method does not ensure the creation of a new EJB instance.